const dgram =  require('dgram');

const server = dgram.createSocket('udp4');

server.on('error', (err) => {
    console.log(`server error:\n${err.stack}`);
    server.close();
});

server.on('listening', () => {
    const address = server.address();
    console.log(`server listening ${address.address}:${address.port}`);
});

server.on('message', (msg, rinfo) => {
    console.log(`got message from ${rinfo.address}:${rinfo.port}`);
    console.log(msg);

    server.send(Buffer.from('get u'), rinfo.port, rinfo.address, (err) => {
        err && console.log(err);
    });
});

server.bind(41234);